package com.cqvip.innocence.project.controller.admin;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqvip.innocence.project.controller.AbstractController;
import com.cqvip.innocence.project.model.dto.JsonResult;
import com.cqvip.innocence.project.model.entity.OperLog;
import com.cqvip.innocence.project.service.OperLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName OperLogController
 * @Description 操作日志
 * @Author Innocence
 * @Date 2020/12/30 16:44
 * @Version 1.0
 */
@RestController
@RequestMapping("/operLog/")
public class OperLogController extends AbstractController {

    @Autowired
    private OperLogService operLogService;

    @GetMapping("getList")
    @ApiOperation("获取操作日志列表")
    public JsonResult getList(OperLog log){
        Page<OperLog> page = getPageParams();
        LambdaQueryWrapper<OperLog> wrapper = new QueryWrapper<OperLog>().lambda();
        wrapper.orderByDesc(OperLog::getCreateTime);
        if (StrUtil.isNotBlank(log.getAdminName())){
            wrapper.eq(OperLog::getAdminName,log.getAdminName());
        }
        if (StrUtil.isNotBlank(log.getRequestMethod())){
            wrapper.eq(OperLog::getRequestMethod,log.getRequestMethod());
        }
        if (StrUtil.isNotBlank(log.getIp())){
            wrapper.eq(OperLog::getIp,log.getIp());
        }
        if (log.getStatus()!=null){
            wrapper.eq(OperLog::getStatus,log.getStatus());
        }
        if (log.getType()!=null){
            wrapper.eq(OperLog::getType,log.getType());
        }
        if (log.getBeginTime()!=null){
            wrapper.ge(OperLog::getCreateTime,log.getBeginTime());
        }
        if (log.getEndTime()!=null){
            wrapper.le(OperLog::getCreateTime,log.getEndTime());
        }
        Page<OperLog> res = operLogService.page(page, wrapper);
        return JsonResult.Get().putPage(res);
    }

}
